home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / PowerClassQueryDevice / PowerClassQueryDevice Read Me next >
Encoding:
Text File  |  2000-04-25  |  6.2 KB  |  93 lines  |  [TEXT/ttxt]

  1. PowerClassQueryDevice v1.0
  2.  
  3.  
  4. PowerClassQueryDevice demonstrates a method for identifying attached USB Power Class devices and accessing the information in the device's usage tables. For information on the USB Power Class, refer to the "Universal Serial Bus Usage Tables for HID Power Devices". You can find a copy of this document from the USB-IF Developer documents web page <http://www.usb.org/developers/devclass.html>. This sample assumes that the developer understands the implementation of the collections of HID usages defined for the device. 
  5.  
  6. The default support provided by the Mac OS USB Power Class is to detect the presence of a USB Power Class HID device, specifically a UPS (Uninterruptible Power Supply) and periodically query the device to detect if the backup power is discharging, and if so whether the level of power remaining has decreased to a programmatically defined limit. When power falls below the "Alert" level, the Mac OS Power Class Driver informs the Power Manager of this low power condition.  The Power Manager displays a low power alert to the user. If the power level continues to decrease, the Power Class driver uses Power Manager 2.0 to shutdown the system.
  7.  
  8. This program sample demonstrates the basic programming required for a UPS vendor to develop a utility appllication or control panel to report the current status of the device and to modify programmable parameters in the Power Class HID usage tables.
  9.  
  10. Requirements
  11.  
  12. This program sample was built using CodeWarrior 4.0, IDE 3.2, with the Universal Interfaces and Libraries v3.3, and the Mac OS USB DDK v1.4.1.
  13.  
  14. This program has been tested on a PowerBook G3 Series system with ADS USB Cardbus card installed running SSW 9.0 and USB v1.4.1f2 with an APS UPS device attached.
  15.  
  16. Implementation
  17.  
  18. The PowerClassQueryDevice demonstrates the use of three calls -
  19.  
  20. GetNextPowerDevice - to identify attached Power Class HID devices
  21. USBPowerGetUsageData - to get usage data
  22. USBPowerSetUsageData - to set usage data.
  23.  
  24. OSStatus GetNextPowerDevice(PowerDeviceDescriptor *device);
  25. Use  GetNextPowerDevice to find all of the Power Class devices and to obtain the USBReference value that is required for the other Power Class device calls.
  26.  
  27. device - a pointer to a PowerDeviceDescriptor structure.  On input, set the device.reference field to the USBReference for the current device.  GetNextPowerDevice fills in the PowerDeviceDescriptor structure with information for the next power class device.  To begin the search, set device.reference to kNoDeviceRef.
  28.  
  29. on return for the call, if the result is noErr, 
  30.     device.vendor - device's vendor ID
  31.     device.product - device's product ID
  32.     device.version - device's version
  33.     device.reference - device's USBReference
  34.  
  35. Result Codes
  36. noErr                             0 - no error
  37. kUSBNoDeviceErr    -6990 - device referenced by device.reference, was not found
  38.  
  39.  
  40. OSStatus USBPowerGetUsageData (USBReference reference, UInt32 inCollection, HIDUsage inUsagePage, HIDUsage inUsage, SInt32 *value);
  41. Use  USBPowerGetUsageData to get the usage value for the specified collection, usage page and usage.
  42.  
  43. reference - USBReference for the specified power class device. 
  44. inCollection - index of the collection to search for the desired usage. Set the index to zero to search in the default collection.
  45. inUsagePage - usage page on which to search.
  46. inUsage - specific usage to return value for.
  47.  
  48. on return from the call, if the result is noErr, value will contain the value for the specified usage.
  49.  
  50. Result Codes
  51. noErr                                       0 - no error
  52. kUSBPending                            1 - the HID request to obtain this value, is pending
  53. kHIDUsageNotFoundErr    -13946 - specified usage not found in the Collection/UsagePage
  54. kUSBUnknownDeviceErr     -6998 - device referenced by device.reference, was not found
  55.  
  56.  
  57. OSStatus USBPowerSetUsageData (USBReference reference, UInt32 inCollection, HIDUsage inUsagePage, HIDUsage inUsage, SInt32 value);
  58. Use  USBPowerSetUsageData to set the usage value for the specified collection, usage page and usage. USBPowerSetUsageData calls HIDSetUsageValue to set the usage value. 
  59.  
  60. reference - USBReference for the specified power class device. 
  61. inCollection - index of the collection to find the desired usage. Set the index to zero to search in the default collection.
  62. inUsagePage - usage page on which to search.
  63. inUsage - specific usage to set value for.
  64.  
  65. on return from the call, if the result is noErr, the new value was set for the specified usage.
  66.  
  67. Result Codes
  68. noErr                                       0 - no error
  69. kUSBPending                            1 - the HID request to obtain this value, is pending
  70. memFullErr                         -108 - insufficient memory to allocate temporary storage
  71. kHIDUsageNotFoundErr    -13946 - specified usage not found on usagepage/collection
  72. kUSBUnknownDeviceErr     -6998 - device referenced by device.reference, was not found
  73. (Errors returned by HIDSetUsageValue are also possible).
  74.  
  75. Using PowerClassQueryDevice
  76.  
  77. The sample program presents the user with the list of USBReferences for attached Power Class devices. Enter the USBReference value for the device you which to query. You must specify whether to get or set a usage value. Whether you set of get a usage value, you must enter the collection number, usage page and usage as hex numbers.  For example, if the first collection contains the PowerDevice usages and I'm interested in the percent load of the power class device, I would enter the following
  78. Collection: 1 
  79. Usage Page: 84 (0x84 is the usage page for PowerDevices - refer to PowerClass.h)
  80. Usage: 35 (0x35 is the usage ID for "Percent Load" - refer to PowerClass.h)
  81.  
  82. If you have called USBPowerGetUsageData, then the percent load or error result will be displayed.  If you have called USBPowerSetUsageData, then the error status in making the call is displayed.
  83.  
  84. It is assumed that the hardware developer will know the collection value to enter for their device in this case. For other developers, the preferred method for accessing the usage information is to use the HID Library API.
  85.  
  86. For comments and bug reports on the USB specific sections of the sample, mail 
  87. <dts@apple.com> with "attn: rkubota" as the first line, and I will try to address them.
  88.  
  89. rich kubota
  90. rkubota@apple.com
  91.  
  92.  
  93.